﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Reviewer.Entities;
using System.Data;
using System.Collections.ObjectModel;
using System.Globalization;
using Reviewer.Utilities.Data;
using MySql.Data.MySqlClient;
using Reviewer.Data.Bases;
using System.Data.SqlClient;

namespace Reviewer.Data
{
    /// <summary>
    /// News Repository
    /// </summary>
    [CLSCompliant(false)]
    public class NewsGameRelationRepository : RepositoryCrudAlternativeBase<NewsGameRelation, Int32, Guid>
    {
        #region fields (private)
        private const string TABLE_NAME = "V2_NewsRelations";
        private static readonly CrudColumnInfo columnId = new CrudColumnInfo(0, "Id", MySqlDbType.Int32, 255, true, false, false, true);
        private static readonly CrudColumnInfo columnNewsId = new CrudColumnInfo(1, "NewsId", MySqlDbType.VarChar, 36, false, true, false);
        private static readonly CrudColumnInfo columnGameId = new CrudColumnInfo(2, "SpilId", MySqlDbType.VarChar, 36, false, false, false);
        #endregion

        #region methods (public)
        #endregion

        #region methods (protected)
        internal override CrudColumnInfo[] Columns
        {
            get
            {
                return new CrudColumnInfo[]{
                    NewsGameRelationRepository.columnId
                    ,NewsGameRelationRepository.columnNewsId
                    ,NewsGameRelationRepository.columnGameId};
            }
        }

        protected override string TableName
        {
            get { return NewsGameRelationRepository.TABLE_NAME; }
        }

        internal override object ColumnToValue(CrudColumnInfo info, NewsGameRelation item)
        {
            if (info.Equals(NewsGameRelationRepository.columnId)) return item.Id;
            else if (info.Equals(NewsGameRelationRepository.columnNewsId)) return item.NewsId;
            else if (info.Equals(NewsGameRelationRepository.columnGameId)) return item.GameId;
            return null;
        }

        protected override NewsGameRelation BuildItemFromReader(IDataReader reader)
        {
            NewsGameRelation item = new NewsGameRelation();
            if (reader != null)
            {
                item.Id = DataReaderUtility.GetValue(reader, reader.GetOrdinal(NewsGameRelationRepository.columnId.Name), 0);
                item.NewsId = DataReaderUtility.GetValue(reader, reader.GetOrdinal(NewsGameRelationRepository.columnNewsId.Name), Guid.Empty);
                item.GameId = DataReaderUtility.GetValue(reader, reader.GetOrdinal(NewsGameRelationRepository.columnGameId.Name), Guid.Empty);
            }
            return item;
        }
        #endregion
    }
}
